package com.tf_cut.backend.agent.service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.tf_cut.backend.common.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tf_cut.backend.agent.pojo.AgentAccount;
import com.tf_cut.backend.agent.repository.AgentAccountRepository;
import com.tf_cut.backend.agent.vo.AgentAndAccountVo;
import com.tf_cut.backend.common.service.CommonServiceImpl;

import java.util.List;

@Service
@Transactional
public class AgentAccountServiceImpl extends CommonServiceImpl<AgentAndAccountVo, AgentAccount, String> implements AgentAccountService {

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private AgentAccountRepository agentAccountRepository;


    /**
     * 根据agentId 得到agentAccount 如果没有 返回null
     * @param agentId
     * @return
     */
    @Override
    public AgentAndAccountVo findAgentAccountIdWithAgentId(String agentId) {

        Result<List<AgentAndAccountVo>> list = this.list(AgentAndAccountVo.builder().agentId(agentId).build());
        if(list.isFlag()&&!list.getData().isEmpty()) {
            AgentAndAccountVo agentAndAccountVo = list.getData().get(0);
            return  agentAndAccountVo;
        }
        return null;

    }
}
